#include<stdio.h>
#include<stdlib.h>
#include<stdbool.h>
#define MAX 10000
typedef struct {
    char data[MAX];
    int top;
} St;
// 初始化
void InitStack(St* st) { st->top = -1; }
// 进栈
void Push(St* st, char c) {
    if (st->top == MAX - 1) {
        return;
    } else {
        st->top++;
        st->data[st->top] = c;
        return;
    }
}
// 出栈
char Out(St* st) {
    if (st->top == -1) {
        return 'F';
    } else {
        char c = st->data[st->top];
        st->top--;
        return c;
    }
}
bool Judge(St* st) {
    if (st->top != -1) {
        return false;
    }
    return true;
}
bool isValid(char* s) {
    St st; // 定义了一个结构体，而不是一个结构体指针
    InitStack(&st);
    int sz = strlen(s);
    if (sz <= 1) {
        return false;
    }
    for (int i = 0; i < sz; i++) {
        if (s[i] == '(' || s[i] == '[' || s[i] == '{') {
            Push(&st, s[i]);
        } else {
            if (s[i] == ')' && Out(&st) != '(') {
                return false;
            } else if (s[i] == ']' && Out(&st) != '[') {
                return false;
            } else if (s[i] == '}' && Out(&st) != '{') {
                return false;
            }
        }
    }
    if (Judge(&st) == false) {
        return false;
    }
    return true;
}